package cn.itcast.hotel.listen;

import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class HotelQueueListen {

    @Autowired
    IHotelService iHotelService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("hotel.insert.queue"),
            exchange = @Exchange(value = "hotel.topic", type = ExchangeTypes.TOPIC),
            key = "hotel.insert"
    ))
    public void listenInserQueue(Long hotelId) {
        log.info("接受到  新增索引库  消息内容==>{}", hotelId);
        iHotelService.insertById(hotelId);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("hotel.delete.queue"),
            exchange = @Exchange(value = "hotel.topic", type = ExchangeTypes.TOPIC),
            key = "hotel.delete"
    ))
    public void listenDeleteQueue(Long hotelId) {
        log.info("接受  到删除索引库  消息内容==>{}", hotelId);
        iHotelService.deleteById(hotelId);
    }
}